Home > Technical Interviews > Computer Science & Engineering > Java Programming > Java Basics Questions and Answers
1. | What is the difference between a constructor and a method? |
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. |
2. | What is the purpose of garbage collection in Java, and when is it used? |
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. |
3. | Describe synchronization in respect to multithreading. |
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. |
4. | What is an abstract class? |
Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (i.e. you may not call its constructor), abstract class may contain static data. |
5. | What is the difference between an Interface and an Abstract class? |
An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. |